{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Copyright 2021-2023 @ Shenzhen Bay Laboratory & Peking University & Huawei Technologies Co., Ltd\n",
    "\n",
    "This code is a part of MindSPONGE:\n",
    "MindSpore Simulation Package tOwards Next Generation molecular modelling.\n",
    "\n",
    "MindSPONGE is open-source software based on the AI-framework:\n",
    "MindSpore (https://www.mindspore.cn/)\n",
    "\n",
    "Licensed under the Apache License, Version 2.0 (the \"License\");\n",
    "you may not use this file except in compliance with the License.\n",
    "\n",
    "You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n",
    "\n",
    "Unless required by applicable law or agreed to in writing, software\n",
    "distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "\n",
    "See the License for the specific language governing permissions and\n",
    "limitations under the License.\n",
    "\n",
    "MindSPONGE advanced tutorial 04: Hybrid enhanced sampling and MetaITS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mindspore import context\n",
    "from mindsponge import Sponge\n",
    "from mindsponge import ForceField\n",
    "from mindsponge import set_global_units\n",
    "from mindsponge import Protein\n",
    "from mindsponge import WithEnergyCell\n",
    "from mindsponge import UpdaterMD\n",
    "from mindsponge.optimizer import SteepestDescent\n",
    "from mindsponge.control import VelocityVerlet\n",
    "from mindsponge.callback import WriteH5MD, RunInfo\n",
    "from mindsponge.control import Langevin\n",
    "from mindsponge.sampling import Metadynamics, ITS\n",
    "from mindsponge.function import VelocityGenerator\n",
    "from mindsponge.colvar import Torsion\n",
    "from mindsponge.function import PI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "context.set_context(mode=context.PYNATIVE_MODE, device_target=\"GPU\")\n",
    "set_global_units('nm', 'kj/mol')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "system = Protein(pdb='alad.pdb')\n",
    "potential = ForceField(system, 'AMBER.FF14SB')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "phi = Torsion([4, 6, 8, 14])\n",
    "psi = Torsion([6, 8, 14, 16])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Using fully connected neighbour list (not updated).\n"
     ]
    }
   ],
   "source": [
    "min_opt = SteepestDescent(system.trainable_params(), 1e-7)\n",
    "mini = Sponge(system, potential, min_opt, metrics={'phi': phi, 'psi': psi})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Started simulation at 2023-05-18 15:41:46\n",
      "[MindSPONGE] Step: 0, E_pot: -55.75643, phi: -3.140886, psi: -3.1410766\n",
      "[MindSPONGE] Step: 10, E_pot: -58.40555, phi: -3.1340268, psi: -3.1368413\n",
      "[MindSPONGE] Step: 20, E_pot: -60.168476, phi: -3.1277595, psi: -3.1337605\n",
      "[MindSPONGE] Step: 30, E_pot: -61.549706, phi: -3.1221528, psi: -3.131402\n",
      "[MindSPONGE] Step: 40, E_pot: -62.696198, phi: -3.1171532, psi: -3.1295478\n",
      "[MindSPONGE] Step: 50, E_pot: -63.674084, phi: -3.112676, psi: -3.1280725\n",
      "[MindSPONGE] Step: 60, E_pot: -64.52254, phi: -3.1086385, psi: -3.1268952\n",
      "[MindSPONGE] Step: 70, E_pot: -65.26819, phi: -3.1049676, psi: -3.1259575\n",
      "[MindSPONGE] Step: 80, E_pot: -65.93031, phi: -3.1016028, psi: -3.1252148\n",
      "[MindSPONGE] Step: 90, E_pot: -66.52346, phi: -3.0984938, psi: -3.1246324\n",
      "[MindSPONGE] Finished simulation at 2023-05-18 15:41:49\n",
      "[MindSPONGE] Simulation time: 3.73 seconds.\n",
      "--------------------------------------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<mindsponge.core.sponge.Sponge at 0x7fd87c337d90>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "run_info = RunInfo(10)\n",
    "mini.run(100, callbacks=[run_info])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "metad = Metadynamics(\n",
    "    colvar=[phi, psi],\n",
    "    update_pace=10,\n",
    "    height=2.5,\n",
    "    sigma=0.05,\n",
    "    grid_min=-PI,\n",
    "    grid_max=PI,\n",
    "    grid_bin=360,\n",
    "    temperature=300,\n",
    "    bias_factor=100,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "its = ITS(\n",
    "    sim_temp=300,\n",
    "    temp_min=270,\n",
    "    temp_max=670,\n",
    "    temp_bin=200,\n",
    "    update_pace=100,\n",
    "    unlinear_temp=True,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Using fully connected neighbour list (not updated).\n"
     ]
    }
   ],
   "source": [
    "sim = WithEnergyCell(system, potential, bias=metad, wrapper=its)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "vgen = VelocityGenerator(300)\n",
    "velocity = vgen(system.shape, system.atom_mass)\n",
    "opt = UpdaterMD(\n",
    "    system,\n",
    "    integrator=VelocityVerlet(system),\n",
    "    thermostat=Langevin(system, 300),\n",
    "    time_step=1e-3,\n",
    "    velocity=velocity\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "md = Sponge(sim, optimizer=opt, metrics={'phi': phi, 'psi': psi})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Started simulation at 2023-05-18 15:41:57\n",
      "[MindSPONGE] Step: 0, E_pot: -79.74093, E_kin: 60.13574, E_tot: -19.60519, Temperature: 229.60847, phi: -3.0927696, psi: -3.1155593\n",
      "[MindSPONGE] Step: 10, E_pot: -119.28449, E_kin: 44.476517, E_tot: -74.807976, Temperature: 169.8189, phi: -3.037634, psi: -3.017646\n",
      "[MindSPONGE] Step: 20, E_pot: -118.148506, E_kin: 44.38232, E_tot: -73.76619, Temperature: 169.45926, phi: -2.9700854, psi: -2.9923446\n",
      "[MindSPONGE] Step: 30, E_pot: -114.2139, E_kin: 44.84871, E_tot: -69.36519, Temperature: 171.24, phi: -2.921324, psi: -3.0061398\n",
      "[MindSPONGE] Step: 40, E_pot: -126.56792, E_kin: 55.20807, E_tot: -71.35985, Temperature: 210.79381, phi: -2.8557289, psi: -3.11261\n",
      "[MindSPONGE] Step: 50, E_pot: -125.0885, E_kin: 59.35125, E_tot: -65.73725, Temperature: 226.61316, phi: -2.839629, psi: 3.0605183\n",
      "[MindSPONGE] Step: 60, E_pot: -119.36946, E_kin: 51.74867, E_tot: -67.62079, Temperature: 197.58522, phi: -2.8968134, psi: 2.9166963\n",
      "[MindSPONGE] Step: 70, E_pot: -127.45937, E_kin: 62.6446, E_tot: -64.81477, Temperature: 239.18774, phi: -2.9331543, psi: 2.8123066\n",
      "[MindSPONGE] Step: 80, E_pot: -120.44443, E_kin: 53.199196, E_tot: -67.24523, Temperature: 203.12358, phi: -2.8599622, psi: 2.8209496\n",
      "[MindSPONGE] Step: 90, E_pot: -140.19995, E_kin: 75.09549, E_tot: -65.10446, Temperature: 286.72736, phi: -2.7373555, psi: 2.9117882\n",
      "[MindSPONGE] Step: 100, E_pot: -117.60074, E_kin: 47.40284, E_tot: -70.1979, Temperature: 180.99211, phi: -2.606741, psi: 2.9623106\n",
      "[MindSPONGE] Step: 110, E_pot: -118.6567, E_kin: 66.523285, E_tot: -52.133415, Temperature: 253.99721, phi: -2.5027995, psi: 2.9605155\n",
      "[MindSPONGE] Step: 120, E_pot: -106.152374, E_kin: 60.75999, E_tot: -45.392384, Temperature: 231.99197, phi: -2.4362724, psi: 2.9245722\n",
      "[MindSPONGE] Step: 130, E_pot: -109.6483, E_kin: 75.19615, E_tot: -34.45215, Temperature: 287.1117, phi: -2.3910851, psi: 2.9104004\n",
      "[MindSPONGE] Step: 140, E_pot: -118.31245, E_kin: 78.404755, E_tot: -39.907692, Temperature: 299.3627, phi: -2.4340427, psi: 2.851014\n",
      "[MindSPONGE] Step: 150, E_pot: -104.953415, E_kin: 75.99011, E_tot: -28.963303, Temperature: 290.1432, phi: -2.4736679, psi: 2.7818432\n",
      "[MindSPONGE] Step: 160, E_pot: -94.767624, E_kin: 73.80617, E_tot: -20.961456, Temperature: 281.8045, phi: -2.4869986, psi: 2.7478561\n",
      "[MindSPONGE] Step: 170, E_pot: -95.31135, E_kin: 76.2936, E_tot: -19.017746, Temperature: 291.30194, phi: -2.4798012, psi: 2.7729053\n",
      "[MindSPONGE] Step: 180, E_pot: -95.884445, E_kin: 65.27335, E_tot: -30.611092, Temperature: 249.22478, phi: -2.427519, psi: 2.7699802\n",
      "[MindSPONGE] Step: 190, E_pot: -100.470604, E_kin: 75.05884, E_tot: -25.411766, Temperature: 286.58743, phi: -2.2506933, psi: 2.743991\n",
      "[MindSPONGE] Step: 200, E_pot: -85.96119, E_kin: 59.38717, E_tot: -26.57402, Temperature: 226.75032, phi: -2.1215415, psi: 2.6842883\n",
      "[MindSPONGE] Step: 210, E_pot: -101.513405, E_kin: 76.483765, E_tot: -25.02964, Temperature: 292.028, phi: -2.1219127, psi: 2.6081324\n",
      "[MindSPONGE] Step: 220, E_pot: -94.60056, E_kin: 67.59804, E_tot: -27.002525, Temperature: 258.1008, phi: -2.270533, psi: 2.580444\n",
      "[MindSPONGE] Step: 230, E_pot: -98.05436, E_kin: 75.02557, E_tot: -23.028786, Temperature: 286.4604, phi: -2.4230144, psi: 2.6321352\n",
      "[MindSPONGE] Step: 240, E_pot: -95.806496, E_kin: 75.48345, E_tot: -20.323044, Temperature: 288.20865, phi: -2.4516025, psi: 2.7004206\n",
      "[MindSPONGE] Step: 250, E_pot: -74.71781, E_kin: 60.943047, E_tot: -13.774765, Temperature: 232.69092, phi: -2.3825808, psi: 2.6954732\n",
      "[MindSPONGE] Step: 260, E_pot: -81.8737, E_kin: 69.74164, E_tot: -12.132065, Temperature: 266.28543, phi: -2.2142532, psi: 2.6511836\n",
      "[MindSPONGE] Step: 270, E_pot: -84.59671, E_kin: 73.546814, E_tot: -11.049896, Temperature: 280.81424, phi: -2.1238115, psi: 2.630606\n",
      "[MindSPONGE] Step: 280, E_pot: -85.83373, E_kin: 86.69067, E_tot: 0.8569336, Temperature: 330.99973, phi: -2.1869392, psi: 2.6231933\n",
      "[MindSPONGE] Step: 290, E_pot: -79.99631, E_kin: 82.221886, E_tot: 2.2255783, Temperature: 313.93713, phi: -2.368892, psi: 2.5941484\n",
      "[MindSPONGE] Step: 300, E_pot: -69.53463, E_kin: 86.71875, E_tot: 17.18412, Temperature: 331.10693, phi: -2.5375898, psi: 2.5203805\n",
      "[MindSPONGE] Step: 310, E_pot: -92.509384, E_kin: 97.89147, E_tot: 5.3820877, Temperature: 373.7663, phi: -2.6273704, psi: 2.4962807\n",
      "[MindSPONGE] Step: 320, E_pot: -68.28911, E_kin: 77.645386, E_tot: 9.356277, Temperature: 296.4633, phi: -2.5939538, psi: 2.4805045\n",
      "[MindSPONGE] Step: 330, E_pot: -75.253174, E_kin: 74.21799, E_tot: -1.0351868, Temperature: 283.3769, phi: -2.4688802, psi: 2.4739726\n",
      "[MindSPONGE] Step: 340, E_pot: -84.858826, E_kin: 80.6589, E_tot: -4.1999283, Temperature: 307.9694, phi: -2.363, psi: 2.423648\n",
      "[MindSPONGE] Step: 350, E_pot: -80.107635, E_kin: 75.534065, E_tot: -4.5735703, Temperature: 288.40192, phi: -2.263954, psi: 2.3932862\n",
      "[MindSPONGE] Step: 360, E_pot: -90.15074, E_kin: 93.00634, E_tot: 2.8555984, Temperature: 355.114, phi: -2.2772238, psi: 2.4720006\n",
      "[MindSPONGE] Step: 370, E_pot: -76.51545, E_kin: 80.62629, E_tot: 4.11084, Temperature: 307.8449, phi: -2.266584, psi: 2.5271018\n",
      "[MindSPONGE] Step: 380, E_pot: -75.33221, E_kin: 71.080666, E_tot: -4.251541, Temperature: 271.39807, phi: -2.198759, psi: 2.5233297\n",
      "[MindSPONGE] Step: 390, E_pot: -72.08569, E_kin: 78.99826, E_tot: 6.912567, Temperature: 301.6288, phi: -2.1160855, psi: 2.5474825\n",
      "[MindSPONGE] Step: 400, E_pot: -97.75255, E_kin: 105.54841, E_tot: 7.7958603, Temperature: 403.00177, phi: -1.9691858, psi: 2.5010486\n",
      "[MindSPONGE] Step: 410, E_pot: -76.8957, E_kin: 85.8654, E_tot: 8.969704, Temperature: 327.84872, phi: -1.8301263, psi: 2.4414833\n",
      "[MindSPONGE] Step: 420, E_pot: -80.27805, E_kin: 83.57306, E_tot: 3.2950058, Temperature: 319.09613, phi: -1.7859201, psi: 2.453263\n",
      "[MindSPONGE] Step: 430, E_pot: -77.88616, E_kin: 90.18403, E_tot: 12.297867, Temperature: 344.33798, phi: -1.6041632, psi: 2.514853\n",
      "[MindSPONGE] Step: 440, E_pot: -87.04277, E_kin: 98.052246, E_tot: 11.009476, Temperature: 374.38013, phi: -1.5446306, psi: 2.676502\n",
      "[MindSPONGE] Step: 450, E_pot: -65.02949, E_kin: 75.45368, E_tot: 10.424194, Temperature: 288.095, phi: -1.5971657, psi: 2.7312543\n",
      "[MindSPONGE] Step: 460, E_pot: -59.807125, E_kin: 69.44963, E_tot: 9.642506, Temperature: 265.17053, phi: -1.5816349, psi: 2.6664257\n",
      "[MindSPONGE] Step: 470, E_pot: -98.17951, E_kin: 113.3351, E_tot: 15.155586, Temperature: 432.7327, phi: -1.6762208, psi: 2.598293\n",
      "[MindSPONGE] Step: 480, E_pot: -66.67237, E_kin: 89.234116, E_tot: 22.561745, Temperature: 340.71103, phi: -1.7605233, psi: 2.6285343\n",
      "[MindSPONGE] Step: 490, E_pot: -85.52496, E_kin: 120.34607, E_tot: 34.821106, Temperature: 459.50177, phi: -1.7619463, psi: 2.6771898\n",
      "[MindSPONGE] Step: 500, E_pot: -55.8295, E_kin: 87.76729, E_tot: 31.93779, Temperature: 335.11044, phi: -1.7338716, psi: 2.8078732\n",
      "[MindSPONGE] Step: 510, E_pot: -52.252556, E_kin: 87.715256, E_tot: 35.4627, Temperature: 334.91177, phi: -1.6416793, psi: 2.8279436\n",
      "[MindSPONGE] Step: 520, E_pot: -56.039597, E_kin: 86.34056, E_tot: 30.300964, Temperature: 329.66293, phi: -1.4844656, psi: 2.8231168\n",
      "[MindSPONGE] Step: 530, E_pot: -74.44821, E_kin: 91.31209, E_tot: 16.863876, Temperature: 348.6451, phi: -1.5000658, psi: 2.8548388\n",
      "[MindSPONGE] Step: 540, E_pot: -86.79652, E_kin: 89.42217, E_tot: 2.6256561, Temperature: 341.42908, phi: -1.5008137, psi: 2.8028507\n",
      "[MindSPONGE] Step: 550, E_pot: -69.80256, E_kin: 62.937675, E_tot: -6.8648834, Temperature: 240.30676, phi: -1.4961536, psi: 2.6954618\n",
      "[MindSPONGE] Step: 560, E_pot: -81.47196, E_kin: 71.6799, E_tot: -9.792061, Temperature: 273.68607, phi: -1.5386411, psi: 2.7460082\n",
      "[MindSPONGE] Step: 570, E_pot: -87.47311, E_kin: 93.8309, E_tot: 6.3577957, Temperature: 358.26236, phi: -1.5895517, psi: 2.8658483\n",
      "[MindSPONGE] Step: 580, E_pot: -64.792885, E_kin: 79.47441, E_tot: 14.681526, Temperature: 303.4468, phi: -1.7661153, psi: 3.042124\n",
      "[MindSPONGE] Step: 590, E_pot: -65.891884, E_kin: 82.24174, E_tot: 16.349854, Temperature: 314.01297, phi: -1.7999774, psi: -3.1209333\n",
      "[MindSPONGE] Step: 600, E_pot: -75.60497, E_kin: 87.28094, E_tot: 11.675964, Temperature: 333.25348, phi: -1.6885825, psi: 3.1117623\n",
      "[MindSPONGE] Step: 610, E_pot: -85.151215, E_kin: 102.739975, E_tot: 17.58876, Temperature: 392.2787, phi: -1.5883836, psi: 3.0314426\n",
      "[MindSPONGE] Step: 620, E_pot: -70.07478, E_kin: 80.989494, E_tot: 10.914711, Temperature: 309.23166, phi: -1.591104, psi: 3.0325859\n",
      "[MindSPONGE] Step: 630, E_pot: -54.793736, E_kin: 67.22429, E_tot: 12.430553, Temperature: 256.67377, phi: -1.6895572, psi: 3.1078074\n",
      "[MindSPONGE] Step: 640, E_pot: -85.059364, E_kin: 80.555954, E_tot: -4.5034103, Temperature: 307.57632, phi: -1.7694314, psi: -3.0815763\n",
      "[MindSPONGE] Step: 650, E_pot: -97.46529, E_kin: 84.76909, E_tot: -12.6961975, Temperature: 323.6628, phi: -1.7869967, psi: -3.074538\n",
      "[MindSPONGE] Step: 660, E_pot: -76.94516, E_kin: 73.43628, E_tot: -3.5088806, Temperature: 280.3922, phi: -1.6569146, psi: -3.1406124\n",
      "[MindSPONGE] Step: 670, E_pot: -79.52424, E_kin: 89.97605, E_tot: 10.451813, Temperature: 343.54388, phi: -1.4833968, psi: 3.0951235\n",
      "[MindSPONGE] Step: 680, E_pot: -64.46858, E_kin: 77.06793, E_tot: 12.59935, Temperature: 294.25845, phi: -1.4076538, psi: 3.084763\n",
      "[MindSPONGE] Step: 690, E_pot: -75.04287, E_kin: 96.26631, E_tot: 21.223442, Temperature: 367.56116, phi: -1.4075203, psi: 3.096728\n",
      "[MindSPONGE] Step: 700, E_pot: -68.46545, E_kin: 86.73877, E_tot: 18.273323, Temperature: 331.18338, phi: -1.5167799, psi: -3.089252\n",
      "[MindSPONGE] Step: 710, E_pot: -62.940178, E_kin: 94.30936, E_tot: 31.369179, Temperature: 360.08914, phi: -1.6223398, psi: -2.9743757\n",
      "[MindSPONGE] Step: 720, E_pot: -71.0504, E_kin: 111.89976, E_tot: 40.849358, Temperature: 427.2523, phi: -1.786952, psi: -2.8623168\n",
      "[MindSPONGE] Step: 730, E_pot: -76.21254, E_kin: 94.8365, E_tot: 18.623962, Temperature: 362.1019, phi: -1.8609877, psi: -2.7851818\n",
      "[MindSPONGE] Step: 740, E_pot: -65.56833, E_kin: 68.486084, E_tot: 2.9177551, Temperature: 261.49152, phi: -1.860178, psi: -2.7737722\n",
      "[MindSPONGE] Step: 750, E_pot: -70.36928, E_kin: 81.60692, E_tot: 11.23764, Temperature: 311.5891, phi: -1.8659747, psi: -2.6964095\n",
      "[MindSPONGE] Step: 760, E_pot: -57.63954, E_kin: 76.24277, E_tot: 18.603226, Temperature: 291.10788, phi: -1.8523581, psi: -2.585906\n",
      "[MindSPONGE] Step: 770, E_pot: -67.75819, E_kin: 74.41908, E_tot: 6.6608963, Temperature: 284.1447, phi: -1.8251485, psi: -2.654468\n",
      "[MindSPONGE] Step: 780, E_pot: -87.7781, E_kin: 83.29796, E_tot: -4.4801407, Temperature: 318.04578, phi: -1.7734948, psi: -2.752952\n",
      "[MindSPONGE] Step: 790, E_pot: -76.04874, E_kin: 79.074524, E_tot: 3.0257874, Temperature: 301.91998, phi: -1.628867, psi: -2.8023274\n",
      "[MindSPONGE] Step: 800, E_pot: -76.52835, E_kin: 83.82252, E_tot: 7.2941666, Temperature: 320.0486, phi: -1.4291472, psi: -2.8861904\n",
      "[MindSPONGE] Step: 810, E_pot: -77.87757, E_kin: 102.272095, E_tot: 24.394524, Temperature: 390.49225, phi: -1.3873676, psi: -2.9029813\n",
      "[MindSPONGE] Step: 820, E_pot: -80.5145, E_kin: 93.81047, E_tot: 13.295967, Temperature: 358.18433, phi: -1.4040849, psi: -2.9969018\n",
      "[MindSPONGE] Step: 830, E_pot: -73.4356, E_kin: 92.307175, E_tot: 18.871574, Temperature: 352.4445, phi: -1.4787576, psi: -3.044232\n",
      "[MindSPONGE] Step: 840, E_pot: -66.79928, E_kin: 92.934, E_tot: 26.13472, Temperature: 354.83783, phi: -1.5597671, psi: -3.0483885\n",
      "[MindSPONGE] Step: 850, E_pot: -62.596466, E_kin: 98.02104, E_tot: 35.424576, Temperature: 374.26102, phi: -1.5458564, psi: -3.0096521\n",
      "[MindSPONGE] Step: 860, E_pot: -67.934746, E_kin: 97.36079, E_tot: 29.42604, Temperature: 371.74005, phi: -1.5013275, psi: -2.938014\n",
      "[MindSPONGE] Step: 870, E_pot: -64.39224, E_kin: 84.630005, E_tot: 20.237762, Temperature: 323.13174, phi: -1.45698, psi: -2.9384403\n",
      "[MindSPONGE] Step: 880, E_pot: -59.24117, E_kin: 83.2186, E_tot: 23.977428, Temperature: 317.74277, phi: -1.4128718, psi: -2.9980183\n",
      "[MindSPONGE] Step: 890, E_pot: -77.000755, E_kin: 102.27911, E_tot: 25.278358, Temperature: 390.51907, phi: -1.4228784, psi: -3.078115\n",
      "[MindSPONGE] Step: 900, E_pot: -81.676994, E_kin: 81.63057, E_tot: -0.046424866, Temperature: 311.6794, phi: -1.526438, psi: 3.0860908\n",
      "[MindSPONGE] Step: 910, E_pot: -74.39573, E_kin: 72.81854, E_tot: -1.5771866, Temperature: 278.0336, phi: -1.6867745, psi: 3.091216\n",
      "[MindSPONGE] Step: 920, E_pot: -68.97943, E_kin: 71.98041, E_tot: 3.0009766, Temperature: 274.83344, phi: -1.7097394, psi: 3.126162\n",
      "[MindSPONGE] Step: 930, E_pot: -86.89314, E_kin: 74.97818, E_tot: -11.914963, Temperature: 286.27945, phi: -1.5113783, psi: 3.0881975\n",
      "[MindSPONGE] Step: 940, E_pot: -87.83422, E_kin: 82.2858, E_tot: -5.548424, Temperature: 314.18115, phi: -1.2800817, psi: 2.9955807\n",
      "[MindSPONGE] Step: 950, E_pot: -92.8027, E_kin: 91.25578, E_tot: -1.5469131, Temperature: 348.43008, phi: -1.1026866, psi: 2.8660507\n",
      "[MindSPONGE] Step: 960, E_pot: -69.02255, E_kin: 55.294525, E_tot: -13.728027, Temperature: 211.1239, phi: -0.96321046, psi: 2.764957\n",
      "[MindSPONGE] Step: 970, E_pot: -91.6662, E_kin: 76.332375, E_tot: -15.333824, Temperature: 291.44998, phi: -0.9526192, psi: 2.6859398\n",
      "[MindSPONGE] Step: 980, E_pot: -88.36425, E_kin: 70.52921, E_tot: -17.835037, Temperature: 269.29254, phi: -1.061979, psi: 2.6602557\n",
      "[MindSPONGE] Step: 990, E_pot: -105.51247, E_kin: 94.7128, E_tot: -10.799667, Temperature: 361.62958, phi: -1.1732504, psi: 2.7381196\n",
      "[MindSPONGE] Finished simulation at 2023-05-18 15:42:26\n",
      "[MindSPONGE] Simulation time: 28.47 seconds.\n",
      "--------------------------------------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<mindsponge.core.sponge.Sponge at 0x7fd7d420b160>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cb_h5md = WriteH5MD(system, 'tutorial_a04.h5md', save_freq=10)\n",
    "md.run(1000, callbacks=[run_info, cb_h5md])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mindspore-1.10",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
